home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Pascal / Snippets / PNL Libraries / MyFullScreen.p < prev    next >
Encoding:
Text File  |  1997-05-02  |  5.5 KB  |  230 lines  |  [TEXT/CWIE]

  1. unit MyFullScreen;
  2.  
  3. interface
  4.  
  5.     uses
  6.         Quickdraw;
  7.         
  8.     const
  9.         fade_to_black_time = 500000;
  10.         fade_in_time = 500000;
  11.     
  12.     const
  13.         kFullScreenOn = true;
  14.         kFullScreenOff = false;
  15.         kDoFade = true;
  16.         kDontFade = false;
  17.         
  18.     var
  19.         full_screen: boolean;
  20.         
  21.     procedure StartupFullScreen;
  22.     procedure SetFullScreen( on, fade: boolean; window: WindowPtr );
  23.     
  24.     procedure FadeTo( percent: integer; time_us: longint );
  25.  
  26. implementation
  27.  
  28.     uses
  29.         Types, LowMem, Menus, Timer, Windows, 
  30.         GammaPaslib,
  31.         MyStartup, MyAssertions, MyWindows;
  32.     
  33.     var
  34.         has_gamma: boolean;
  35.         current_fade: integer;
  36.         
  37. { /-------------------------------------------------------------------------------------- }
  38. {     Globals for HideMenuBar and ShowMenuBar }
  39. { /-------------------------------------------------------------------------------------- }
  40.  
  41.     var
  42.  
  43.         gOldVisRgn: RgnHandle;    {  visRgn of window before hiding menu bar }
  44.         gOldMBarHeight: integer;
  45.         gFadeWindow: WindowPtr;
  46.  
  47. { Hide/ShowMenuBar from SpriteWorld 2.0 }
  48.  
  49. { /-------------------------------------------------------------------------------------- }
  50. {     HideMenuBar - expands the vis region of grafPort to cover the entire window, which }
  51. {  will allow you to draw in the top of that window to erase the menu bar. This is a }
  52. {  simple routine designed for programs with only one window that covers the menu bar. }
  53. {  If you need to expand the region of more than one window, you need a different routine. }
  54. {  Be sure to make the window visible before calling this. HideMenuBar returns the }
  55. {  region of the menu bar and corners of the screen, in case you want to erase or }
  56. {  draw in that area. }
  57. { /-------------------------------------------------------------------------------------- }
  58.  
  59.     procedure HideMenuBar (grafPort: GrafPtr);
  60.         var
  61.             newVisRgn: RgnHandle;
  62.             savePort: GrafPtr;
  63.     begin
  64.         if (gOldVisRgn <> nil) then begin
  65.             exit(HideMenuBar);
  66.         end;
  67.  
  68.         GetPort(savePort);
  69.         SetPort(grafPort);
  70.  
  71.         gOldMBarHeight := LMGetMBarHeight;
  72.         LMSetMBarHeight(0);        {  Keeps things like SuperClock from coming on. }
  73.  
  74.         {  save off vis region }
  75.         gOldVisRgn := NewRgn;
  76.         CopyRgn(grafPort^.visRgn, gOldVisRgn);
  77.  
  78.         {  expand the vis region of the port rect to be completely rectangular }
  79.         newVisRgn := NewRgn;
  80.         RectRgn(newVisRgn, grafPort^.portRect);
  81.         CopyRgn(newVisRgn, grafPort^.visRgn);
  82.         DisposeRgn(newVisRgn);
  83.  
  84.         SetPort(savePort);
  85.     end;
  86.  
  87. { /-------------------------------------------------------------------------------------- }
  88. {     ShowMenuBar - restores the grafPort to the way it was before the call to HideMenuBar. }
  89. {     Make sure to call this after every call to HideMenuBar to dispose of gOldVisRgn. }
  90. { /-------------------------------------------------------------------------------------- }
  91.  
  92.     procedure ShowMenuBar (grafPort: GrafPtr);
  93.         var
  94.             savePort: GrafPtr;
  95.             junkRgn: RgnHandle;
  96.  
  97.     begin
  98.  
  99.         if (gOldVisRgn = nil) then
  100.             exit(ShowMenuBar);
  101.  
  102.         GetPort(savePort);
  103.         SetPort(grafPort);
  104.  
  105.         LMSetMBarHeight(gOldMBarHeight);
  106.  
  107.         {  fill the rounded corners of the screen with black again }
  108.         junkRgn := NewRgn;
  109.         CopyRgn(gOldVisRgn, junkRgn);
  110.         DiffRgn(grafPort^.visRgn, junkRgn, junkRgn);
  111.  
  112. {$IFC undefined THINK_Pascal}
  113.         FillRgn(junkRgn, qd.black);
  114. {$ELSEC}
  115.         FillRgn(junkRgn, black);
  116. {$ENDC}
  117.  
  118.         DisposeRgn(junkRgn);
  119.  
  120.         {  restore the old vis region }
  121.         CopyRgn(gOldVisRgn, grafPort^.visRgn);
  122.         DisposeRgn(gOldVisRgn);
  123.         gOldVisRgn := nil;
  124.  
  125.         DrawMenuBar;
  126.  
  127.         SetPort(savePort);
  128.     end;
  129.  
  130.     procedure FadeTo( percent: integer; time_us: longint );
  131.         var
  132.             last, now: UnsignedWide;
  133.             junk: OSErr;
  134.     begin
  135.         if has_gamma & (percent <> current_fade) then begin
  136.             time_us := time_us div abs(percent - current_fade);
  137.             Microseconds( last );
  138.             while current_fade <> percent do begin
  139.                 if percent > current_fade then begin
  140.                     Inc(current_fade);
  141.                 end else begin
  142.                     Dec(current_fade);
  143.                 end;
  144.                 junk := DoGammaFade( current_fade );
  145.                 repeat
  146.                     Microseconds( now );
  147.                 until now.lo - last.lo > time_us;
  148.                 last.lo := last.lo + time_us;
  149.             end;
  150.         end;
  151.         current_fade := percent;
  152.     end;
  153.  
  154.     procedure SetFullScreen( on, fade: boolean; window: WindowPtr );
  155.         var
  156.             frame: Rect;
  157.     begin
  158.         if on <> full_screen then begin
  159.         
  160.             if window = nil then begin
  161.                 Assert( gFadeWindow <> nil );
  162.                 window := gFadeWindow;
  163.             end else begin
  164.                 gFadeWindow := window;
  165.             end;
  166.             
  167.             if fade then begin
  168.                 FadeTo( 0, fade_to_black_time );
  169.             end;
  170.  
  171.             if on then begin
  172.                 UnionRect( GetGrayRgn^^.rgnBBox, qd.screenBits.bounds, frame );
  173.                 SetWindowRect( window, frame );
  174.                 LMSetPaintWhite( 0 );
  175.                 ShowWindow( window );
  176.                 HideMenuBar( window );
  177.                 SetPort( window );
  178.                 FillRect( frame, qd.black );
  179.                 LMSetPaintWhite( -1 );
  180.                 if fade then begin
  181.                     FadeTo( 100, 0 );
  182.                 end;
  183.             end else begin
  184.                 ShowMenuBar( window );
  185.                 HideWindow( window );
  186.                 DrawMenuBar;
  187.                 if fade then begin
  188.                     FadeTo( 100, fade_in_time );
  189.                 end;
  190.             end;
  191.             
  192.             full_screen := on;
  193.         end;
  194.     end;
  195.     
  196.     function InitFullScreen( var msg: integer ): OSStatus;
  197.     begin
  198. {$unused(msg)}
  199.         has_gamma := IsGammaAvailable;
  200. //        has_gamma := false;
  201.         
  202.         current_fade := 100;
  203.         full_screen := false;
  204.         gOldVisRgn := nil;
  205.         if has_gamma then begin
  206.             has_gamma := has_gamma & (SetupGammaTools = noErr);
  207.         end;
  208.         InitFullScreen := noErr;
  209.     end;
  210.  
  211.     procedure FinishFullScreen;
  212.         var
  213.             junk: OSErr;
  214.     begin
  215.         if full_screen then begin
  216.             SetFullScreen( kFullScreenOff, kDontFade, gFadeWindow );
  217.         end;
  218.         if has_gamma then begin
  219.             FadeTo( 100, 0 );
  220.             junk := DisposeGammaTools;
  221.         end;
  222.     end;
  223.     
  224.     procedure StartupFullScreen;
  225.     begin
  226.         SetStartup( InitFullScreen, nil, 0, FinishFullScreen );
  227.     end;
  228.     
  229. end.
  230.